<html>
<head><meta charset="utf-8"><title>Formatting question · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Formatting.20question.html">Formatting question</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="210317911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Formatting%20question/near/210317911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ender <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Formatting.20question.html#210317911">(Sep 16 2020 at 20:42)</a>:</h4>
<p>Hi, I am simply a newbie learning Rust. I came over from JavaScript.</p>
<p>I'm going through Rust by Example and having a hard time with <a href="https://doc.rust-lang.org/rust-by-example/hello/print.html">formatted print</a>. It seems random. Is there a really simple version of <a href="https://doc.rust-lang.org/rust-by-example/hello/print.html">this</a> made for simpletons or five year olds that I can read? I don't see any patterns.</p>



<a name="210318589"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Formatting%20question/near/210318589" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Formatting.20question.html#210318589">(Sep 16 2020 at 20:48)</a>:</h4>
<p>there's a more in-depth explanation at <a href="https://doc.rust-lang.org/std/fmt/">https://doc.rust-lang.org/std/fmt/</a></p>



<a name="210319286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Formatting%20question/near/210319286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pachi <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Formatting.20question.html#210319286">(Sep 16 2020 at 20:55)</a>:</h4>
<p>@ender also format! is to build strings, while print!, println! is similar to console.log() and eprint! eprintln! to console.error() IIRC</p>



<a name="210320181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Formatting%20question/near/210320181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ender <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Formatting.20question.html#210320181">(Sep 16 2020 at 21:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/122651-general/topic/Formatting.20question/near/210318589">said</a>:</p>
<blockquote>
<p>there's a more in-depth explanation at <a href="https://doc.rust-lang.org/std/fmt/">https://doc.rust-lang.org/std/fmt/</a></p>
</blockquote>
<p>Yay, I figured it out!</p>



<a name="210320424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Formatting%20question/near/210320424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> ender <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Formatting.20question.html#210320424">(Sep 16 2020 at 21:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125416">pachi</span> <a href="#narrow/stream/122651-general/topic/Formatting.20question/near/210319286">said</a>:</p>
<blockquote>
<p>@ender also format! is to build strings, while print!, prinln! is similar to console.log() and eprint! eprintln! to console.error() IIRC</p>
</blockquote>
<p>Did you mean "println!"? That's the only thing you mentioned I've learned so far. Excited for the rest :-)</p>



<a name="210323427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Formatting%20question/near/210323427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pachi <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Formatting.20question.html#210323427">(Sep 16 2020 at 21:35)</a>:</h4>
<p><span class="user-mention" data-user-id="341972">@ender</span> yes, sorry for the typo</p>



<a name="210330972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Formatting%20question/near/210330972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Formatting.20question.html#210330972">(Sep 16 2020 at 23:09)</a>:</h4>
<p><code>format!</code> is Rust's equivalent of template strings in JS:</p>
<h1>Rust</h1>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;person&quot;</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">greeting</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">format</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;Hello, {}!&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">name</span><span class="p">);</span><span class="w"></span>
</code></pre></div>


<h1>JavaScript</h1>
<div class="codehilite"><pre><span></span><code><span class="kr">const</span> <span class="nx">name</span> <span class="o">=</span> <span class="s2">&quot;person&quot;</span><span class="p">;</span>
<span class="kr">const</span> <span class="nx">greeting</span> <span class="o">=</span> <span class="sb">`Hello, </span><span class="si">${</span><span class="nx">name</span><span class="si">}</span><span class="sb">!`</span><span class="p">;</span>
</code></pre></div>


<p>Not sure if that's helpful, but figured I'd put an example.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>